using SanJ.FreeCare.Shared;
using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc.Rendering;
using Volo.Abp.Application.Dtos;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using SanJ.FreeCare.Medications;

namespace SanJ.FreeCare.Web.Pages.Medications
{
    public abstract class CreateModalModelBase : FreeCarePageModel
    {

        [BindProperty]
        public MedicationCreateViewModel Medication { get; set; }

        protected IMedicationsAppService _medicationsAppService;

        public CreateModalModelBase(IMedicationsAppService medicationsAppService)
        {
            _medicationsAppService = medicationsAppService;

            Medication = new();
        }

        public virtual async Task OnGetAsync()
        {
            Medication = new MedicationCreateViewModel();

            await Task.CompletedTask;
        }

        public virtual async Task<IActionResult> OnPostAsync()
        {

            await _medicationsAppService.CreateAsync(ObjectMapper.Map<MedicationCreateViewModel, MedicationCreateDto>(Medication));
            return NoContent();
        }
    }

    public class MedicationCreateViewModel : MedicationCreateDto
    {
    }
}